use {
    solana_program::pubkey::Pubkey,
    solana_program_test::{ProgramTest, *},
    spl_associated_token_account::{id, processor::process_instruction},
};

#[allow(dead_code)]
pub fn program_test(token_mint_address: Pubkey, use_latest_spl_token: bool) -> ProgramTest {
    let mut pc = ProgramTest::new(
        "spl_associated_token_account",
        id(),
        processor!(process_instruction),
    );

    if use_latest_spl_token {
        pc.prefer_bpf(false);
        // TODO: Remove when spl-token is available by default in program-test
        pc.add_program(
            "spl_token",
            spl_token::id(),
            processor!(spl_token::processor::Processor::process),
        );
    }

    // Add a token mint account
    //
    // The account data was generated by running:
    //      $ solana account EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
    //                       --output-file tests/fixtures/token-mint-data.bin
    //
    pc.add_account_with_file_data(
        token_mint_address,
        1461600,
        spl_token::id(),
        "token-mint-data.bin",
    );

    // Dial down the BPF compute budget to detect if the program gets bloated in the
    // future
    pc.set_compute_max_units(60_000);

    pc
}

#[allow(dead_code)]
pub fn program_test_2022(
    token_mint_address: Pubkey,
    use_latest_spl_token_2022: bool,
) -> ProgramTest {
    let mut pc = ProgramTest::new(
        "spl_associated_token_account",
        id(),
        processor!(process_instruction),
    );

    if use_latest_spl_token_2022 {
        pc.prefer_bpf(false);
        // TODO: Remove when spl-token-2022 is available by default in program-test
        pc.add_program(
            "spl_token_2022",
            spl_token_2022::id(),
            processor!(spl_token_2022::processor::Processor::process),
        );
    }

    // Add a token mint account
    //
    // The account data was generated by running:
    //      $ solana account EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
    //                       --output-file tests/fixtures/token-mint-data.bin
    //
    pc.add_account_with_file_data(
        token_mint_address,
        1461600,
        spl_token_2022::id(),
        "token-mint-data.bin",
    );

    // Dial down the BPF compute budget to detect if the program gets bloated in the
    // future
    pc.set_compute_max_units(50_000);

    pc
}
